package com.innovations.inn.service.impl;

import java.util.List;
import com.innovations.common.utils.DateUtils;
import com.innovations.common.utils.uuid.IdGeneratorSnowflake;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.innovations.inn.mapper.MessageNotificationMapper;
import com.innovations.inn.domain.MessageNotification;
import com.innovations.inn.service.IMessageNotificationService;

/**
 * 消息通知Service业务层处理
 * 
 * @author dp
 * @date 2024-08-09
 */
@Service
public class MessageNotificationServiceImpl implements IMessageNotificationService 
{
    @Autowired
    private MessageNotificationMapper messageNotificationMapper;
    @Autowired
    IdGeneratorSnowflake idGeneratorSnowflake;

    /**
     * 查询消息通知
     * 
     * @param messageNotificationId 消息通知主键
     * @return 消息通知
     */
    @Override
    public MessageNotification selectMessageNotificationByMessageNotificationId(Long messageNotificationId)
    {
        return messageNotificationMapper.selectMessageNotificationByMessageNotificationId(messageNotificationId);
    }

    /**
     * 查询消息通知列表
     * 
     * @param messageNotification 消息通知
     * @return 消息通知
     */
    @Override
    public List<MessageNotification> selectMessageNotificationList(MessageNotification messageNotification)
    {
        return messageNotificationMapper.selectMessageNotificationList(messageNotification);
    }

    /**
     * 新增消息通知
     * 
     * @param messageNotification 消息通知
     * @return 结果
     */
    @Override
    public int insertMessageNotification(MessageNotification messageNotification)
    {
        messageNotification.setCreateTime(DateUtils.getNowDate());
        return messageNotificationMapper.insertMessageNotification(messageNotification);
    }

    /**
     * 修改消息通知
     * 
     * @param messageNotification 消息通知
     * @return 结果
     */
    @Override
    public int updateMessageNotification(MessageNotification messageNotification)
    {
        return messageNotificationMapper.updateMessageNotification(messageNotification);
    }

    /**
     * 批量删除消息通知
     * 
     * @param messageNotificationIds 需要删除的消息通知主键
     * @return 结果
     */
    @Override
    public int deleteMessageNotificationByMessageNotificationIds(Long[] messageNotificationIds)
    {
        return messageNotificationMapper.deleteMessageNotificationByMessageNotificationIds(messageNotificationIds);
    }

    /**
     * 删除消息通知信息
     * 
     * @param messageNotificationId 消息通知主键
     * @return 结果
     */
    @Override
    public int deleteMessageNotificationByMessageNotificationId(Long messageNotificationId)
    {
        return messageNotificationMapper.deleteMessageNotificationByMessageNotificationId(messageNotificationId);
    }

    /**
     * 实体数据补全
     *
     * @param messageNotification 实体
     * @param userId       用户id
     * @param crateType    创建类型 1：新增 2：修改
     */
    @Override
    public void completeData(MessageNotification messageNotification, Long userId, Integer crateType) {
        //主键
        if (messageNotification.getMessageNotificationId() == null || "".equals(messageNotification.getMessageNotificationId())) {
            messageNotification.setMessageNotificationId(idGeneratorSnowflake.nextId());
        }
        //创建人、创建时间
        if (crateType == 1) {
            if (messageNotification.getCreateBy() == null || "".equals(messageNotification.getCreateBy())) {
                messageNotification.setCreateBy(userId);
            }
            if (messageNotification.getCreateTime() == null) {
                messageNotification.setCreateTime(DateUtils.getNowDate());
            }
        }
//        //修改人
//        if (messageNotification.getModifyBy() == null) {
//            messageNotification.setModifyBy(userId);
//        }
//        //修改时间
//        if (messageNotification.getModifyTime() == null) {
//            messageNotification.setModifyTime(DateUtils.getNowDate());
//        }
    }
}
